<?php

/**
* Joomla :: Multilang_M17n v1.5.8
* Multilang info@groenewegdigitaal, M17n joomla@sdic.ch
* http://www.groenewegdigitaal.nl, http://www.sdic.ch
**/

function com_uninstall () {
	global $mainframe;
	global $dirs,$save,$copy;
	
	$db=JFactory::getDBO();
	$db->setQuery("DELETE FROM `#__modules` WHERE module='mod_M17n' LIMIT 1");
	$db->query();
	$db->setQuery("DELETE FROM `#__plugins` WHERE element='M17n' AND folder='system' LIMIT 1");
	$db->query();
	
	// Files Definition List
	$dirs=Array(
		'modules/mod_M17n/icons',
		'modules/mod_M17n'
	);
	
	// Unhacked files to save
	$save=Array(
		'administrator/components/com_menus/views/item/tmpl/form.php',
		'administrator/components/com_menus/views/list/tmpl/default.php',
		'administrator/components/com_menus/views/list/view.php',
		'administrator/components/com_menus/models/list.php',
		
		'libraries/joomla/application/menu.php',
		
		'modules/mod_mainmenu/helper.php',
		'modules/mod_mainmenu/legacy.php',
		'modules/mod_mainmenu/mod_mainmenu.php',
		'modules/mod_mainmenu/mod_mainmenu.xml',
		'modules/mod_mainmenu/tmpl/default.php',
//  hack multilang
		'components/com_content/models/frontpage.php',
		'components/com_content/models/category.php',
		'components/com_content/models/section.php',
		'components/com_content/controller.php',
		'plugins/search/content.php',
		'modules/mod_mostread/helper.php',
		'modules/mod_latestnews/helper.php', 
		'modules/mod_newsflash/helper.php' ,
// end hack multilang					
	);
	
	// Packed files to copy
	$copy=Array(
		'administrator/components/com_menus/views/item/tmpl/form.php',
		'administrator/components/com_menus/views/list/tmpl/default.php',
		'administrator/components/com_menus/views/list/view.php',
		'administrator/components/com_menus/models/list.php',
		
		'libraries/joomla/application/menu.php',
		
		'modules/mod_mainmenu/helper.php',
		'modules/mod_mainmenu/legacy.php',
		'modules/mod_mainmenu/mod_mainmenu.php',
		'modules/mod_mainmenu/mod_mainmenu.xml',
		'modules/mod_mainmenu/tmpl/default.php',
		
		'modules/mod_M17n/index.html',
		'modules/mod_M17n/mod_M17n.php',
		'modules/mod_M17n/mod_M17n.xml',
		'modules/mod_M17n/icons/index.html',
		'modules/mod_M17n/icons/af-ZA.gif',
		'modules/mod_M17n/icons/ar-AE.gif',
		'modules/mod_M17n/icons/ar-BH.gif',
		'modules/mod_M17n/icons/ar-DZ.gif',
		'modules/mod_M17n/icons/ar-EG.gif',
		'modules/mod_M17n/icons/ar-IQ.gif',
		'modules/mod_M17n/icons/ar-JO.gif',
		'modules/mod_M17n/icons/ar-KW.gif',
		'modules/mod_M17n/icons/ar-LB.gif',
		'modules/mod_M17n/icons/ar-LY.gif',
		'modules/mod_M17n/icons/ar-MA.gif',
		'modules/mod_M17n/icons/ar-OM.gif',
		'modules/mod_M17n/icons/ar-QA.gif',
		'modules/mod_M17n/icons/ar-SA.gif',
		'modules/mod_M17n/icons/ar-SY.gif',
		'modules/mod_M17n/icons/ar-TN.gif',
		'modules/mod_M17n/icons/ar-YE.gif',
		'modules/mod_M17n/icons/az-AZ.gif',
		'modules/mod_M17n/icons/be-BY.gif',
		'modules/mod_M17n/icons/bg-BG.gif',
		'modules/mod_M17n/icons/bn-BD.gif',
		'modules/mod_M17n/icons/bs-BA.gif',
		'modules/mod_M17n/icons/ca-AD.gif',
		'modules/mod_M17n/icons/ca-ES.gif',
		'modules/mod_M17n/icons/co-FR.gif',
		'modules/mod_M17n/icons/cs-CZ.gif',
		'modules/mod_M17n/icons/cy-GB.gif',
		'modules/mod_M17n/icons/da-DK.gif',
		'modules/mod_M17n/icons/de-AT.gif',
		'modules/mod_M17n/icons/de-CH.gif',
		'modules/mod_M17n/icons/de-DE.gif',
		'modules/mod_M17n/icons/de-LI.gif',
		'modules/mod_M17n/icons/div-MV.gif',
		'modules/mod_M17n/icons/dz-BT.gif',
		'modules/mod_M17n/icons/el-CY.gif',
		'modules/mod_M17n/icons/el-GR.gif',
		'modules/mod_M17n/icons/en-AG.gif',
		'modules/mod_M17n/icons/en-AU.gif',
		'modules/mod_M17n/icons/en-BB.gif',
		'modules/mod_M17n/icons/en-BW.gif',
		'modules/mod_M17n/icons/en-BZ.gif',
		'modules/mod_M17n/icons/en-CA.gif',
		'modules/mod_M17n/icons/en-GB.gif',
		'modules/mod_M17n/icons/en-JM.gif',
		'modules/mod_M17n/icons/en-NZ.gif',
		'modules/mod_M17n/icons/en-TT.gif',
		'modules/mod_M17n/icons/en-US.gif',
		'modules/mod_M17n/icons/en-ZW.gif',
		'modules/mod_M17n/icons/eo-EO.gif',
		'modules/mod_M17n/icons/es-AR.gif',
		'modules/mod_M17n/icons/es-BO.gif',
		'modules/mod_M17n/icons/es-CL.gif',
		'modules/mod_M17n/icons/es-CO.gif',
		'modules/mod_M17n/icons/es-CR.gif',
		'modules/mod_M17n/icons/es-CU.gif',
		'modules/mod_M17n/icons/es-DO.gif',
		'modules/mod_M17n/icons/es-EC.gif',
		'modules/mod_M17n/icons/es-ES.gif',
		'modules/mod_M17n/icons/es-GT.gif',
		'modules/mod_M17n/icons/es-HN.gif',
		'modules/mod_M17n/icons/es-MX.gif',
		'modules/mod_M17n/icons/es-NI.gif',
		'modules/mod_M17n/icons/es-PA.gif',
		'modules/mod_M17n/icons/es-PE.gif',
		'modules/mod_M17n/icons/es-PY.gif',
		'modules/mod_M17n/icons/es-SV.gif',
		'modules/mod_M17n/icons/es-UY.gif',
		'modules/mod_M17n/icons/es-VE.gif',
		'modules/mod_M17n/icons/et-ES.gif',
		'modules/mod_M17n/icons/eu-ES.gif',
		'modules/mod_M17n/icons/fa-IR.gif',
		'modules/mod_M17n/icons/fi-FI.gif',
		'modules/mod_M17n/icons/fo-FO.gif',
		'modules/mod_M17n/icons/fr-BF.gif',
		'modules/mod_M17n/icons/fr-BJ.gif',
		'modules/mod_M17n/icons/fr-CA.gif',
		'modules/mod_M17n/icons/fr-CH.gif',
		'modules/mod_M17n/icons/fr-CI.gif',
		'modules/mod_M17n/icons/fr-FR.gif',
		'modules/mod_M17n/icons/fr-MC.gif',
		'modules/mod_M17n/icons/fr-TD.gif',
		'modules/mod_M17n/icons/fy-NL.gif',
		'modules/mod_M17n/icons/ga-IE.gif',
		'modules/mod_M17n/icons/gl-ES.gif',
		'modules/mod_M17n/icons/he-IL.gif',
		'modules/mod_M17n/icons/hr-HR.gif',
		'modules/mod_M17n/icons/hu-HU.gif',
		'modules/mod_M17n/icons/hy-AM.gif',
		'modules/mod_M17n/icons/id-ID.gif',
		'modules/mod_M17n/icons/is-IS.gif',
		'modules/mod_M17n/icons/it-CH.gif',
		'modules/mod_M17n/icons/it-IT.gif',
		'modules/mod_M17n/icons/ja-JP.gif',
		'modules/mod_M17n/icons/ka-GE.gif',
		'modules/mod_M17n/icons/kk-KZ.gif',
		'modules/mod_M17n/icons/km-KH.gif',
		'modules/mod_M17n/icons/ko-KP.gif',
		'modules/mod_M17n/icons/ko-KR.gif',
		'modules/mod_M17n/icons/ku-KU.gif',
		'modules/mod_M17n/icons/la-VA.gif',
		'modules/mod_M17n/icons/lb-LU.gif',
		'modules/mod_M17n/icons/lt-LT.gif',
		'modules/mod_M17n/icons/lv-LV.gif',
		'modules/mod_M17n/icons/mk-MK.gif',
		'modules/mod_M17n/icons/mn-MN.gif',
		'modules/mod_M17n/icons/ms-BN.gif',
		'modules/mod_M17n/icons/ms-MY.gif',
		'modules/mod_M17n/icons/mt-MT.gif',
		'modules/mod_M17n/icons/nb-NO.gif',
		'modules/mod_M17n/icons/ne-NP.gif',
		'modules/mod_M17n/icons/nl-BE.gif',
		'modules/mod_M17n/icons/nl-NL.gif',
		'modules/mod_M17n/icons/nn-NO.gif',
		'modules/mod_M17n/icons/pl-PL.gif',
		'modules/mod_M17n/icons/ps-AF.gif',
		'modules/mod_M17n/icons/pt-AO.gif',
		'modules/mod_M17n/icons/pt-BR.gif',
		'modules/mod_M17n/icons/pt-PT.gif',
		'modules/mod_M17n/icons/rm-CH.gif',
		'modules/mod_M17n/icons/rn-BI.gif',
		'modules/mod_M17n/icons/ro-RO.gif',
		'modules/mod_M17n/icons/ru-RU.gif',
		'modules/mod_M17n/icons/si-LK.gif',
		'modules/mod_M17n/icons/sk-SK.gif',
		'modules/mod_M17n/icons/sl-SL.gif',
		'modules/mod_M17n/icons/sq-AL.gif',
		'modules/mod_M17n/icons/sr-SP.gif',
		'modules/mod_M17n/icons/sv-SE.gif',
		'modules/mod_M17n/icons/sw-KE.gif',
		'modules/mod_M17n/icons/th-TH.gif',
		'modules/mod_M17n/icons/tr-TR.gif',
		'modules/mod_M17n/icons/tt-RU.gif',
		'modules/mod_M17n/icons/uk-UA.gif',
		'modules/mod_M17n/icons/uz-UZ.gif',
		'modules/mod_M17n/icons/vi-VN.gif',
		'modules/mod_M17n/icons/wa-BE.gif',
		'modules/mod_M17n/icons/zh-CHS.gif',
		'modules/mod_M17n/icons/zh-CHT.gif',
		'modules/mod_M17n/icons/zh-CN.gif',
		'modules/mod_M17n/icons/zh-SG.gif',
		'modules/mod_M17n/icons/zh-TW.gif',
		
		'plugins/system/M17n.php',
		'plugins/system/M17n.xml',
		
//  hack multilang
		'components/com_content/models/frontpage.php',
		'components/com_content/models/category.php',
		'components/com_content/models/section.php',
		'plugins/search/content.php',
		'modules/mod_mostread/helper.php',
		'modules/mod_latestnews/helper.php', 
		'modules/mod_newsflash/helper.php' ,
// end hack multilang			
	);
	
	$rootPath=JPATH_ROOT;
	
	uncopyFiles($rootPath);
	clearFiles($rootPath);
	
	$db=JFactory::getDBO();
	$db->setQuery("DELETE FROM `#__modules` WHERE module='mod_M17n'");
	$db->query();
	$db->setQuery("DELETE FROM `#__plugins` WHERE element='M17n' AND folder='system'");
	$db->query();
	
	$module_msg="Successfully Uninstalled Joomla :: M17n Package";
	
	echo "<p>$module_msg</p>";
	
}

// Function to remove the files (remove files, remove dirs, restore originals)
function uncopyFiles($basePath){
	global $dirs,$save,$copy;
	
	if(subStr($basePath,-1)!='/')$basePath.='/';
	
	$basePath=str_replace("\\","/",$basePath);
	
	$fromPath=$basePath.'administrator/components/com_m17n/';
	
	$fsdirs=new JFolder();
	$fslink=new JFile();
	
	foreach($copy as $src){
		// Removes installed file
		$dest=$basePath.$src;
		$fslink->delete($dest);
		// Removes package file
		$dest=$fromPath.$src;
		if(file_exists($dest))$fslink->delete($dest);
	}
	
	foreach($dirs as $dir){
		$folder=$basePath.$dir;
		if(is_dir($folder)) $fsdirs->delete($folder);
	}
	
	foreach($save as $bak){
		$new=str_replace(Array('.php','.xml','.html'),Array('.bak.php','.bak.xml','.bak.html'),$bak);
		$oldPath=$basePath.$bak;
		$newPath=$basePath.$new;
		if(file_exists($newPath))$fslink->move($newPath,$oldPath);
	}
}

// Function to clean package (removes dirs from install folder)
function clearFiles($basePath){
	
	$fsdirs=new JFolder();
	$fslink=new JFile();
	
	if(subStr($basePath,-1)!='/')$basePath.='/';
	$fromPath=$basePath.'administrator/components/com_m17n';
	
	if(is_dir($fromPath.'/modules/mod_mainmenu/tmpl'))$fsdirs->delete($fromPath.'/modules/mod_mainmenu/tmpl');
	if(is_dir($fromPath.'/modules/mod_mainmenu'))$fsdirs->delete($fromPath.'/modules/mod_mainmenu');
	if(is_dir($fromPath.'/modules/mod_M17n'))$fsdirs->delete($fromPath.'/modules/mod_M17n');
	if(is_dir($fromPath.'/modules'))$fsdirs->delete($fromPath.'/modules');
	if(is_dir($fromPath.'/administrator/components/com_menus/views/list/tmpl'))$fsdirs->delete($fromPath.'/administrator/components/com_menus/views/list/tmpl');
	if(is_dir($fromPath.'/administrator/components/com_menus/views/list'))$fsdirs->delete($fromPath.'/administrator/components/com_menus/views/list');
	if(is_dir($fromPath.'/administrator/components/com_menus/views/item/tmpl'))$fsdirs->delete($fromPath.'/administrator/components/com_menus/views/item/tmpl');
	if(is_dir($fromPath.'/administrator/components/com_menus/views/item'))$fsdirs->delete($fromPath.'/administrator/components/com_menus/views/item');
	if(is_dir($fromPath.'/administrator/components/com_menus/views'))$fsdirs->delete($fromPath.'/administrator/components/com_menus/views');
	if(is_dir($fromPath.'/administrator/components/com_menus/models'))$fsdirs->delete($fromPath.'/administrator/components/com_menus/models');
	if(is_dir($fromPath.'/administrator/components/com_menus'))$fsdirs->delete($fromPath.'/administrator/components/com_menus');
	if(is_dir($fromPath.'/administrator/components'))$fsdirs->delete($fromPath.'/administrator/components');
	if(is_dir($fromPath.'/libraries/joomla/application'))$fsdirs->delete($fromPath.'/libraries/joomla/application');
	if(is_dir($fromPath.'/libraries/joomla'))$fsdirs->delete($fromPath.'/libraries/joomla');
	if(is_dir($fromPath.'/libraries'))$fsdirs->delete($fromPath.'/libraries');
	if(is_dir($fromPath.'/administrator'))$fsdirs->delete($fromPath.'/administrator');
	if(is_dir($fromPath.'/plugins/system'))$fsdirs->delete($fromPath.'/plugins/system');
	if(is_dir($fromPath.'/plugins'))$fsdirs->delete($fromPath.'/plugins');
//  hack multilang				
//	if(is_dir($fromPath.'/components/com_content/models/frontpage.php'))$fsdirs->delete($fromPath.'/components/com_content/models/frontpage.php');
//	if(is_dir($fromPath.'/components/com_content/models/category.php'))$fsdirs->delete($fromPath.'/components/com_content/models/category.php');
//	if(is_dir($fromPath.'/components/com_content/models/section.php'))$fsdirs->delete($fromPath.'/components/com_content/models/section.php');
//	if(is_dir($fromPath.'/plugins/search/content.php'))$fsdirs->delete($fromPath.'/plugins/search/content.php');
//	if(is_dir($fromPath.'/modules/mod_mostread/helper.php'))$fsdirs->delete($fromPath.'/modules/mod_mostread/helper.php');
//	if(is_dir($fromPath.'/modules/mod_latestnews/helper.php'))$fsdirs->delete($fromPath.'/modules/mod_latestnews/helper.php');
//	if(is_dir($fromPath.'/modules/mod_newsflash/helper.php'))$fsdirs->delete($fromPath.'/modules/mod_newsflash/helper.php');
// end hack multilang			
	if(file_exists($fromPath.'/M17n.xml'))$fslink->delete($fromPath.'/M17n.xml');
	if(file_exists($fromPath.'/install.M17n.php'))$fslink->delete($fromPath.'/install.M17n.php');
	if(file_exists($fromPath.'/uninstall.M17n.php'))$fslink->delete($fromPath.'/uninstall.M17n.php');
	
	
	if(is_dir($fromPath))$fsdirs->delete($fromPath);
}

?>
